package com.hdsx.restful.glzt.structure.jkss.rest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.stereotype.Service;

import com.hdsx.restful.base.PreparedDataListener;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Znode;
import com.hdsx.restful.glzt.structure.jkss.bean.Jkss;
import com.hdsx.restful.glzt.structure.jkss.service.JkssService;
import com.hdsx.restful.glzt.structure.ql.bean.StatisticalResult;
import com.hdsx.restful.util.CheckEmpty;
import com.hdsx.restful.util.Dao;
import com.hdsx.restful.util.EasyUI;


@Path("/jksxsb")
@Service
public class JkssRestServer {
    @Resource(name = "jkssServiceImpl")
    private JkssService server;


    @GET
    @Path("/getListByLxbm")
    @Produces(MediaType.APPLICATION_JSON)
    public EasyUI<Jkss> getListByLxbm(@QueryParam("lxbm") String lxbm,@QueryParam("page") int page,@QueryParam("rows") int rows){
        EasyUI<Jkss> easyUI=new EasyUI<Jkss>(page,rows);
        int count =server.queryJkssCountByLxbm(lxbm);
        List<Jkss> qlListByLxbm = server.getListByLxbm(lxbm,easyUI.getBegin(),easyUI.getEnd());
        easyUI.setTotal(count);
        easyUI.setRows(qlListByLxbm);
        return easyUI;
    }

    @GET
    @Path("/getListByXzqhbm")
    @Produces(MediaType.APPLICATION_JSON)
    public EasyUI<Jkss> getListByXzqhbm(@QueryParam("xzqhbm") String xzqhbm,@QueryParam("page") int page,@QueryParam("rows") int rows){
        EasyUI<Jkss> easyUI=new EasyUI<Jkss>(page,rows);
        int count =server.queryJkssCountXzqhbm(xzqhbm);
        List<Jkss> qlListByXzqhbm = server.getListByXzqhbm(xzqhbm,easyUI.getBegin(),easyUI.getEnd());
        easyUI.setTotal(count);
        easyUI.setRows(qlListByXzqhbm);
        return easyUI;
    }


    /**
     * http://192.168.0.137:8080/restful/rest/jkss/list?lxbm=G65&xzqhbm=610116&jkssmc=彩色云台摄&page=0&rows=10
     * @param lxbm
     * @param xzqhbm
     * @param jkssmc
     * @param page
     * @param rows
     * @return
     */
    @GET
    @Path("/list")
    @Produces(MediaType.APPLICATION_JSON)
    public EasyUI<Jkss> getList(@QueryParam("lxbm") String lxbm,@QueryParam("xzqhbm")String xzqhbm,
			@QueryParam("sxxfx") String sxxfx,@QueryParam("qdzh") String qdzh_string,
			@QueryParam("zdzh") String zdzh_string,@QueryParam("name") String name,
			@QueryParam("page") int page,@QueryParam("rows") int rows) throws Exception{
		EasyUI<Jkss> easyUI=new EasyUI<Jkss>(page,rows);
		Double qdzh = null;
		Double zdzh = null;
		try{
			qdzh = Double.parseDouble(qdzh_string);
			zdzh = Double.parseDouble(zdzh_string);
		}catch(Exception e){
			System.out.println("qdzh和zdzh没有输入或格式错误！");qdzh=null;zdzh=null;
		}
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		int count =server.queryCount(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name);
		List<Jkss> results = server.queryList(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name,easyUI.getBegin(),easyUI.getEnd());
		easyUI.setTotal(count);
		easyUI.setRows(results);
		return easyUI;
	}


    @GET
    @Path("/getByjkssbh")
    @Produces(MediaType.APPLICATION_JSON)
    public Jkss getByJkssbm(@QueryParam("jkssbh") String jkssbh){
        Jkss jkss = server.getOne(jkssbh);
        return jkss;
    }


    @GET
    @Path("/info")
    @Produces(MediaType.APPLICATION_JSON)
    public List<Dao>  getShapeById(@QueryParam("id") String id) {
        List<Dao> list = server.getShapeById(id);
        return list;
    }
    @GET
    @Path("/tjjg")
    @Produces(MediaType.APPLICATION_JSON)
    public StatisticalResult getStatisticalResult(@QueryParam("szlx") String szlx,@QueryParam("xzqhbm") String xzqhbm,@QueryParam("type") String type){
    	xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
    	Map<String, Object> map = new HashMap<String, Object>();
        map.put("lxbm", szlx);
        map.put("xzqhbm", xzqhbm);
        map.put("type", type);
        StatisticalResult tjjg = server.countByParameter(map);
        return tjjg;
    }
    @GET
   	@Path("/Node")
   	@Produces(MediaType.APPLICATION_JSON)
   	public List<Znode> tree(){
   		return PreparedDataListener.getData("jkss");
//    	return server.jkssNode();
   	}
    
	@GET
	@Path("/detail")
	@Produces(MediaType.APPLICATION_JSON)
	public EasyUI<Jkss> detail(@QueryParam("szlx") String szlx,@QueryParam("xzqhbm") String xzqhbm,
			@QueryParam("lxfl") String lxfl,@QueryParam("ztfl") String ztfl,@QueryParam("page") int page,@QueryParam("rows") int rows){
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		EasyUI<Jkss> easyUI = new EasyUI<Jkss>(page, rows);
		Map<String, Object> map = easyUI.getParameter();
		map.put("lxbm", szlx);
		map.put("xzqhbm", xzqhbm);
		try{
			map.put("lxfl", Integer.parseInt(lxfl));
		}catch (Exception e){
			System.out.println("不是类型分类！");
		}
		try{
			map.put("ztfl", Integer.parseInt(ztfl));
		}catch (Exception e){
			System.out.println("不是状态分类！");
		}
		List<Jkss> detail = server.detail(map);
		int total = server.countDetail(map);
		easyUI.setRows(detail);
		easyUI.setTotal(total);
		return easyUI;
	}
    
	@GET
	@Path("/all")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Jkss> all(@QueryParam("lxbm") String lxbm,@QueryParam("xzqhbm")String xzqhbm,
			@QueryParam("sxxfx") String sxxfx,@QueryParam("qdzh") String qdzh_string,
			@QueryParam("zdzh") String zdzh_string,@QueryParam("name") String name){
		Double qdzh = null;
		Double zdzh = null;
		try{
			qdzh = Double.parseDouble(qdzh_string);
			zdzh = Double.parseDouble(zdzh_string);
		}catch(Exception e){
			System.out.println("qdzh和zdzh没有输入或格式错误！");qdzh=null;zdzh=null;
		}
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		List<Jkss> list = server.listAll(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name);
		return list;
	}
	
	@GET
	@Path("/one")
	@Produces(MediaType.APPLICATION_JSON)
	public Jkss one(@QueryParam("id")String id){
		Jkss one = server.queryById(id);
		return one;
	}
	
	@GET
	@Path("/auto")
	@Produces(MediaType.APPLICATION_JSON)
	public List<String> pienext(@QueryParam("name")String name){
		return server.selectName(name);
	}
}
